package liuwanghui.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import liuwanghui.dto.request.*;
import liuwanghui.pojo.Result;
import liuwanghui.service.SaleOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/sale-orders")
@RequiredArgsConstructor
@CrossOrigin
@Tag(name = "销售订单", description = "销售订单相关接口")
public class SaleOrderController {

    private final SaleOrderService saleOrderService;

    @GetMapping
    @Operation(summary = "获取订单列表")
    public Result getSaleOrders(SaleOrderQueryDTO params) {
        return saleOrderService.getSaleOrders(params);
    }

    @PostMapping
    @Operation(summary = "创建订单")
    public Result createOrder(@RequestBody @Valid SaleOrderCreateDTO dto) {
        return saleOrderService.createOrder(dto);
    }

    @PostMapping("/{id}/cancel")
    @Operation(summary = "取消订单")
    public Result cancelOrder(@PathVariable Long id) {
        saleOrderService.cancelOrder(id);
        return Result.success();
    }

    @PostMapping("/{id}/confirm")
    @Operation(summary = "确认收货")
    public Result confirmReceipt(@PathVariable Long id) {
        saleOrderService.confirmReceipt(id);
        return Result.success();
    }

    @PostMapping("/{id}/review")
    @Operation(summary = "评价订单")
    public Result reviewOrder(
            @PathVariable Long id,
            @RequestBody @Valid SaleOrderReviewDTO dto) {
        saleOrderService.reviewOrder(id, dto);
        return Result.success();
    }
} 